﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PloobsEngine.SceneControl;
using PloobsEngine.Physics;
using PloobsEngine.Modelo;
using PloobsEngine.Material;
using PloobsEngine.Engine;
using PloobsEngine.Physics.Bepu;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using PloobsEngine.Cameras;
using Microsoft.Xna.Framework.Input;
using PloobsProjectTemplate.Screens;
using PloobsEngine.Light;
//using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
//using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using PloobsEngine.Input;


namespace PloobsProjectTemplate.Screens
{
    /// <summary>
    /// Basic Forward Screen
    /// </summary>
    public class Intro : IScene
    {
        
        
        /// <summary>
        /// Sets the world and render technich.
        /// </summary>
        /// <param name="renderTech">The render tech.</param>
        /// <param name="world">The world.</param>
        protected override void SetWorldAndRenderTechnich(out IRenderTechnic renderTech, out IWorld world)
        {
            ///create the IWorld
            world = new IWorld(new BepuPhysicWorld(-0.97f, true, 1), new SimpleCuller());
            
            ///Create the deferred technich
            //ForwardRenderTecnichDescription desc = new ForwardRenderTecnichDescription();
            //renderTech = new ForwardRenderTecnich(desc);
            DeferredRenderTechnicInitDescription desc = DeferredRenderTechnicInitDescription.Default();
            desc.DefferedDebug = false;
            desc.UseFloatingBufferForLightMap = false;
            renderTech = new DeferredRenderTechnic(desc);
        }

        /// <summary>
        /// Load content for the screen.
        /// </summary>
        /// <param name="GraphicInfo"></param>
        /// <param name="factory"></param>
        /// <param name="contentManager"></param>
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            #region "TieFighter"
            IModelo mTieFighter = new SimpleModel(factory, "TieFighter");
            
            TriangleMeshObject tmesh = new TriangleMeshObject(mTieFighter, new Vector3(0, 0, 0), Matrix.Identity, Vector3.One);
            
            IShader shader = new ForwardXNABasicShader(new ForwardXNABasicShaderDescription(Color.Red,Color.Red, Color.Red));
            
            IMaterial mat = new DeferredMaterial(shader);
            
            TieFighter tieFighter = new TieFighter(tmesh, mat, mTieFighter);

            this.World.AddObject(tieFighter);
            #endregion
           
            ICamera cam = new CameraFollowObject(tieFighter, new Vector3(1, 0, -1));
        
            this.World.CameraManager.AddCamera(cam);

            SimpleConcreteKeyboardInputPlayable ik1 = new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS, Keys.A, g1, InputMask.G1);
            this.BindInput(ik1);  

        }
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }
    
        /// <summary>
        /// This is called when the screen should draw itself.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="render"></param>
        protected override void Draw(GameTime gameTime, RenderHelper render)
        {
            base.Draw(gameTime, render);

            ///Draw some text on the screen
            render.RenderTextComplete("INTRO", new Vector2(GraphicInfo.Viewport.Width - 315, 15), Color.White, Matrix.Identity);

        }

        public void g1(InputPlayableKeyBoard ipk)
        {
            ScreenManager.RemoveScreen(this);
            ScreenManager.AddScreen(new Menu());
        }

    }
}
